import $http from '../../http/http.js'
import apiSetting from '../../http/apiSetting.js'
let dayjs = require('dayjs');
let app = getApp();
Page({
  data: {
    name: '',
    type: '',
    passType: '',
    isTreePack: false,
    treeData: []
  },

  onLoad(query) {
    this.data.type = query.type
    this.data.passType = query.passType
    this.data.noStorage = query.noStorage
    this.factoryTree()
  },

  factoryTree() {
    let that = this
    $http(apiSetting.factoryTree, {
      search: that.data.name
    }).then((data) => {
      that.setData({
        treeData: data.result,
        isTreePack: true
      })
    })
  },

  onChengCheck(data) {
    if (this.data.noStorage) {
      const pages = getCurrentPages();
      let currPage = pages[pages.length - 1]; //当前页面
      let prevPage = pages[pages.length - 2]; //上一个页面
      prevPage.data.getSelectRange = true
      prevPage.data.selectRangeData = data
    } else {
      dd.setStorage({
        key: 'selectFacScope',
        data: data
      });
    }
    let url = '/pages/' + this.data.passType + '/' + this.data.passType
    if (this.data.type == "back") {
      dd.navigateBack({
        delta: 1
      })
    } else {
      dd.redirectTo({
        url: url
      })
    }
  },

  onInputName(e) {
    this.data.name = e.detail.value
  }

});
